# 构建用户画像
import csv
import io
import json
import sys

from flask import jsonify
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.metrics.pairwise import cosine_similarity
from py2neo import Graph
import pandas as pd
import mysql.connector

from bulid_distance import city_similarity, read_cities_data, get_ex_cities

sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8')
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')


class UserProfile:
    def __init__(self, job_id):
        self.job_id = job_id


# def recommend_positions(user_profile, knowledge_graph):


if __name__ == '__main__':
    # 获取通过命令行传递的参数
    id = sys.argv[1]

    graph = Graph("http://47.109.43.77/:7474", auth=("neo4j", "Xiyou666"), name="neo4j")

    # 根据公司名获取岗位信息
    # 定义 Cypher 查询语句
    cypher_query = """
    MATCH (job:job)
    WHERE job.id = $id
    RETURN job.name,job.description,job.company,job.address,job.education,job.link,job.salary
    """

    # 执行查询，并返回结果
    result_category = graph.run(cypher_query,id=id)

    if result_category:
        results = []
        for result in result_category:
            job_info = {
                "name": result['job.name'],
                "description": result['job.description'],
                "company": result['job.company'],
                "address": result['job.address'],
                "education": result['job.education'],
                "link": result['job.link'],
                "salary": result['job.salary']
            }
            results.append(job_info)

        # 返回封装好的 JSON 对象
        print(json.dumps(results, ensure_ascii=False))
